package com.nowcoder.community.entity;

/**
 * @author tang
 * @create 2020-10-25
 */

/**
 * 封装分页相关信息
 */
public class Page {

    //当前的页码
    private int current =1;
    //limit on everypage
    private int limit=10;
    //total pages
    private int rows;
    //url
    private String path;

    public int getOffset(){
        return (current-1)*limit;
    }

    public int getTotal(){
        if (rows%limit==0){
            return rows/limit;
        }
        else {
            return  rows/limit+1;
        }
    }

    /**
     * get from page
     * @return
     */
    public int getFrom(){
          int from= current-2;
          return from<1? 1:from;
    }

    /**
     * get to page
     */
    public int getTo(){
        int to = current+2;
        int total =getTotal();
        return to > total ? total : to;
    }
    public int getCurrent() {
        return current;
    }

    public void setCurrent(int current) {
        this.current = current;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

}
